﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>StrCompare - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The StrCompare function compares two strings alphabetically." />
<meta name="ahk:equiv-v1" content="AutoHotkey.htm" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css">
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>StrCompare</h1>
<p>按字母顺序比较两个字符串.</p>
<pre class="Syntax">Result := <span class="func">StrCompare</span>(String1, String2 <span class="optional">, CaseSense := false</span>)</pre>

<h2 id="Parameters">参数</h2>
<dl>
  <dt>String1, String2</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>要比较的字符串.</p>
  </dd>
  <dt>CaseSense</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a>或<a href="../Concepts.htm#strings">字符串</a></p>
    <p>One of the following values (defaults to 0 if omitted):</p>
    <p><code>"On"</code> or <code>1</code> (<code>True</code>): The comparison is case sensitive.</p>
    <p><code>"Off"</code> or <code>0</code> (<code>False</code>): The letters A-Z are considered identical to their lowercase counterparts.</p>
    <p id="Locale"><code>"Locale"</code>: The comparison is case insensitive according to the rules of the current user's locale. For example, most English and Western European locales treat not only the letters A-Z as identical to their lowercase counterparts, but also non-ASCII letters like &Auml; and &Uuml; as identical to theirs. <em>Locale</em> is 1 to 8 times slower than <em>Off</em> depending on the nature of the strings being compared.</p>
    <p><code>"Logical"</code>: Like <em>Locale</em>, but digits in the strings are considered as numerical content rather than text. For example, "A2" is considered less than "A10". However, if two numbers differ only by the presence of a leading zero, the string with leading zero may be considered <em>less</em> than the other string. The exact behavior may differ between OS versions.</p>
    <p>如果参数 <em>CaseSensitive</em> 被省略或为 0(false), 则比较不区分大小写(不区分的方法取决于 <a href="StringCaseSense.htm">StringCaseSense</a>); 否则, 大小写必须完全匹配, 才能认为字符串是相同的.</p>
  </dd>
</dl>

<h2 id="Return_Value">返回值</h2>
<p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
<p>指示 <em>String1</em> 和 <em>String2</em> 之间的关系, 该函数返回以下内容之一:</p>
<ul>
  <li>0, 如果 <em>String1</em> 等于 <em>String2</em></li>
  <li>正整数, 如果 <em>String1</em> 大于 <em>String2</em></li>
  <li>负整数, 如果 <em>String1</em> 小于 <em>String2</em></li>
</ul>
<p>To check for a specific relationship between the two strings, compare the result to 0. For example:</p>
<pre>a_less_than_b := StrCompare(a, b) &lt; 0
a_greater_than_or_equal_to_b := StrCompare(a, b) &gt;= 0</pre>

<h2 id="Remarks">备注</h2>
<p>此函数通常用于 <a href="Sort.htm#callback">sort 回调</a>.</p>

<h2 id="Related">相关</h2>
<p><a href="Sort.htm">Sort</a></p>

<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>
MsgBox StrCompare("Abc", "abc") <em>; 返回 0</em>
MsgBox StrCompare("Abc", "abc", true) <em>; 返回 -1</em>
</pre>
</div>

</body>
</html>